﻿#region DaAssSubBranch
/*----------------------------------------------------------------
// 文件名：DaAssSubBranch.cs
// 功能描述：类AssSubBranch的数据访问层
//
// 
// 创建时间：2009-07-10 DtataAccess template . Ver 5.0.20090413
//
// 修改标识： 
// 修改描述： 
//----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.Text;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using Las.Model; 


namespace Las.Dal
{
	///可以继承更上层接口,IAssSubBranch ,数据访问层基类DaBase，
	///DaBase中包含了DbException异常处理静态方法
    public	partial  class DaAssSubBranch:DaBase<MoAssSubBranch>
    {	 
		#region SQL const
		internal const string TABLE_COLUMNS=" ASIS_ID ,ASS_SUB_BRANCH_ID ,ASS_SUB_BRANCH_NAME ,ASB_LEV   ";
		
		internal const string SQL_INSERT="INSERT INTO LA_ASS_SUB_BRANCH ("+TABLE_COLUMNS+") VALUES (@AsisId,@AssSubBranchId,@AssSubBranchName,@AsbLev)";
		internal const string SQL_SELECT="SELECT "+TABLE_COLUMNS+" FROM LA_ASS_SUB_BRANCH  ";
		internal const string SQL_SELECT_ONE=SQL_SELECT+" WHERE ASIS_ID=@AsisId AND  ASS_SUB_BRANCH_ID=@AssSubBranchId";                              
		
		internal const string SQL_EXIST="SELECT COUNT(*) FROM LA_ASS_SUB_BRANCH  WHERE ASIS_ID=@AsisId and  ASS_SUB_BRANCH_ID=@AssSubBranchId  ";
		internal const string SQL_UPDATE="UPDATE LA_ASS_SUB_BRANCH SET ASS_SUB_BRANCH_NAME=@AssSubBranchName, ASB_LEV=@AsbLev WHERE ASIS_ID=@AsisId AND  ASS_SUB_BRANCH_ID=@AssSubBranchId";
		
		internal const string SQL_DELETE_DEFAULT = "DELETE FROM LA_ASS_SUB_BRANCH ";
		internal const string SQL_DELETE="DELETE FROM LA_ASS_SUB_BRANCH WHERE ASIS_ID=@AsisId AND  ASS_SUB_BRANCH_ID=@AssSubBranchId";
		
		internal const string SQL_COUNT="SELECT COUNT(*) FROM LA_Ass_Sub_Branch";
		#endregion
		       
		#region Constructor
	 
		/// <summary>
        /// 默认构造函数，使用配置文件中默认的数据库配置。
        /// </summary>
		public DaAssSubBranch ()
		{ 
			this.db=DatabaseFactory.CreateDatabase();
		}
		/// <summary>
        /// 使用指定的databaseName数据库配置。
        /// </summary>
        /// <param name="databaseName">配置文件中数据库的配置名称。</param>
		public DaAssSubBranch (string databaseName)
		{ 
            this.db = DatabaseFactory.CreateDatabase(databaseName);
		} 
		
		public DaAssSubBranch (Database db)
		{ 
            this.db = db;
		} 
		
		#endregion
		
		//以下是CRUD方法，每个方法都有引入外部事务的版本

		#region 构造器模块
		
        protected override MoAssSubBranch ConstructT()
        {
            return new MoAssSubBranch();
        }
        #endregion
		
	    
		
		#region Add模块 Helper
		
		///build the command object.It never throw exception.
		protected override  DbCommand ConstructAddCommand(Database db)
		{
			DbCommand dbCommand = db.GetSqlStringCommand(SQL_INSERT);
			 
			db.AddInParameter(dbCommand,"AsisId",DbType.AnsiString);
			db.AddInParameter(dbCommand,"AssSubBranchId",DbType.AnsiString);
			db.AddInParameter(dbCommand,"AssSubBranchName",DbType.String);
			db.AddInParameter(dbCommand,"AsbLev",DbType.AnsiString);
			return dbCommand;
		}		
		protected override DbCommand ConstructAddCommand(Database db,MoAssSubBranch entity)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_INSERT);			 
			db.AddInParameter(dbCommand,"AsisId",DbType.AnsiString,entity.AsisId);
			db.AddInParameter(dbCommand,"AssSubBranchId",DbType.AnsiString,entity.AssSubBranchId);
			db.AddInParameter(dbCommand,"AssSubBranchName",DbType.String,entity.AssSubBranchName);
			db.AddInParameter(dbCommand,"AsbLev",DbType.AnsiString,entity.AsbLev);
			return dbCommand;
		}
		
		protected override DbCommand PopulateAddCommandParameters(Database db,DbCommand addCmd,MoAssSubBranch entity)
		{
			db.SetParameterValue(addCmd,"AsisId",entity.AsisId);
			db.SetParameterValue(addCmd,"AssSubBranchId",entity.AssSubBranchId);
			db.SetParameterValue(addCmd,"AssSubBranchName",entity.AssSubBranchName);
			db.SetParameterValue(addCmd,"AsbLev",entity.AsbLev);
			return addCmd;
		}
		
		protected override DbCommand PopulateAddCommandParameters(Database db,DbCommand addCmd,DataRow row)
		{
			db.SetParameterValue(addCmd,"AsisId",row["AsisId"]);
			db.SetParameterValue(addCmd,"AssSubBranchId",row["AssSubBranchId"]);
			db.SetParameterValue(addCmd,"AssSubBranchName",row["AssSubBranchName"]);
			db.SetParameterValue(addCmd,"AsbLev",row["AsbLev"]);
			return addCmd;
		}
		
		#endregion
		    
		#region Update模块 Helper
		
		protected override DbCommand ConstructUpdateCommand(Database db)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_UPDATE);		    
			db.AddInParameter(dbCommand,"AssSubBranchName",DbType.String);
			db.AddInParameter(dbCommand,"AsbLev",DbType.AnsiString);
			db.AddInParameter(dbCommand,"AsisId",DbType.AnsiString);
			db.AddInParameter(dbCommand,"AssSubBranchId",DbType.AnsiString);
			 
			return dbCommand;
		}
		protected override DbCommand ConstructUpdateCommand(Database db,MoAssSubBranch entity)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_UPDATE);		    
			db.AddInParameter(dbCommand,"AssSubBranchName",DbType.String,entity.AssSubBranchName);
			db.AddInParameter(dbCommand,"AsbLev",DbType.AnsiString,entity.AsbLev);
			db.AddInParameter(dbCommand,"AsisId",DbType.AnsiString,entity.AsisId);
			db.AddInParameter(dbCommand,"AssSubBranchId",DbType.AnsiString,entity.AssSubBranchId);
			 
			return dbCommand;
		}
		
		protected override DbCommand PopulateUpdateCommandParameters(Database db,DbCommand updateCmd,MoAssSubBranch entity)
		{
			db.SetParameterValue(updateCmd,"AssSubBranchName",entity.AssSubBranchName);
			db.SetParameterValue(updateCmd,"AsbLev",entity.AsbLev);
			db.SetParameterValue(updateCmd,"AsisId",entity.AsisId);
			db.SetParameterValue(updateCmd,"AssSubBranchId",entity.AssSubBranchId);
			return updateCmd;
		}
		protected override DbCommand PopulateUpdateCommandParameters(Database db,DbCommand updateCmd,DataRow row)
		{
			db.SetParameterValue(updateCmd,"AssSubBranchName",row["AssSubBranchName"]);
			db.SetParameterValue(updateCmd,"AsbLev",row["AsbLev"]);
			db.SetParameterValue(updateCmd,"AsisId",row["AsisId"]);
			db.SetParameterValue(updateCmd,"AssSubBranchId",row["AssSubBranchId"]);
			return updateCmd;
		}
		
		protected override void PrepareDataAdapterCommand(Database db,out DbCommand dbInsertCommand,
		                     out DbCommand dbUpdateCommand,out DbCommand dbDeleteCommand)
		{
			dbInsertCommand = db.GetSqlStringCommand(SQL_INSERT);
			#region set insert cmd parameters
			db.AddInParameter(dbInsertCommand, "AsisId",DbType.AnsiString, "ASIS_ID", DataRowVersion.Current);
			db.AddInParameter(dbInsertCommand, "AssSubBranchId",DbType.AnsiString, "ASS_SUB_BRANCH_ID", DataRowVersion.Current);
			db.AddInParameter(dbInsertCommand, "AssSubBranchName",DbType.String, "ASS_SUB_BRANCH_NAME", DataRowVersion.Current);
			db.AddInParameter(dbInsertCommand, "AsbLev",DbType.AnsiString, "ASB_LEV", DataRowVersion.Current);
			#endregion
			dbUpdateCommand = db.GetSqlStringCommand(SQL_UPDATE);
			#region Set update cmd value parameters
			db.AddInParameter(dbUpdateCommand, "AssSubBranchName", DbType.String, "ASS_SUB_BRANCH_NAME", DataRowVersion.Current);
			db.AddInParameter(dbUpdateCommand, "AsbLev", DbType.AnsiString, "ASB_LEV", DataRowVersion.Current);
			#endregion
			#region set update cmd pk where parameters
			db.AddInParameter(dbUpdateCommand, "AsisId", DbType.AnsiString, "ASIS_ID", DataRowVersion.Current);
			db.AddInParameter(dbUpdateCommand, "AssSubBranchId", DbType.AnsiString, "ASS_SUB_BRANCH_ID", DataRowVersion.Current);
			#endregion			
			dbDeleteCommand = db.GetSqlStringCommand(SQL_DELETE);
			#region set delete cmd pk where parameters
			db.AddInParameter(dbDeleteCommand, "AsisId", DbType.AnsiString, "ASIS_ID", DataRowVersion.Current);
			db.AddInParameter(dbDeleteCommand, "AssSubBranchId", DbType.AnsiString, "ASS_SUB_BRANCH_ID", DataRowVersion.Current);
			#endregion
		}
		#endregion	
		
		#region Delete模块 Helper		
		
		protected override DbCommand ConstructDeleteCommand(Database db)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_DELETE);
			 
			db.AddInParameter(dbCommand,"AsisId",DbType.AnsiString);
			db.AddInParameter(dbCommand,"AssSubBranchId",DbType.AnsiString);
			 
			return dbCommand;
		}		
		protected override DbCommand ConstructDeleteCommand(Database db,MoAssSubBranch entity)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_DELETE);
			 
			db.AddInParameter(dbCommand,"AsisId",DbType.AnsiString,entity.AsisId);
			db.AddInParameter(dbCommand,"AssSubBranchId",DbType.AnsiString,entity.AssSubBranchId);
		 
			return dbCommand;
		}
		
		protected override DbCommand ConstructDeleteCommandForWhere(Database db, string where)
        {
            return db.GetSqlStringCommand(SQL_DELETE_DEFAULT + where);            
        }

        protected override DbCommand PopulateDeleteCommandParameters(Database db, DbCommand deleteCmd, MoAssSubBranch entity)
        {
			db.SetParameterValue(deleteCmd,"AsisId",entity.AsisId);
			db.SetParameterValue(deleteCmd,"AssSubBranchId",entity.AssSubBranchId);
			return deleteCmd;
        }

        protected override DbCommand PopulateDeleteCommandParameters(Database db, DbCommand deleteCmd, DataRow row)
        {
			db.SetParameterValue(deleteCmd,"AsisId",row["AsisId"]);
			db.SetParameterValue(deleteCmd,"AssSubBranchId",row["AssSubBranchId"]);
			return deleteCmd;
        }      
		
		#endregion helper
		
		#region Query模块 Helper

        protected override DbCommand ConstructQueryCommand(string condition)
        {
            return db.GetSqlStringCommand(SQL_SELECT + condition);
        }

        #endregion
		
		#region GetEntity(s)模块 Helper
        
		protected override DbCommand ConstructSelectOneCommand(Database db,MoAssSubBranch entity)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_SELECT_ONE);
			 
			db.AddInParameter(dbCommand,"AsisId",DbType.AnsiString,entity.AsisId);
			db.AddInParameter(dbCommand,"AssSubBranchId",DbType.AnsiString,entity.AssSubBranchId);
			return dbCommand;
		}
		
		protected override void PopulateEntityByDataReader(IDataReader reader,ref MoAssSubBranch entity)
		{
			if (!reader.IsDBNull(0)) entity.AsisId = reader.GetString(0);
			if (!reader.IsDBNull(1)) entity.AssSubBranchId = reader.GetString(1);
			if (!reader.IsDBNull(2)) entity.AssSubBranchName = reader.GetString(2);
			if (!reader.IsDBNull(3)) entity.AsbLev = reader.GetString(3);
		}
		
		

        protected override DbCommand ConstructSelectConditionCommand(Database db, string condition)
        {
            return db.GetSqlStringCommand(SQL_SELECT + condition);
        }
		
		#endregion	
		
		#region Count模块 Helper

        protected override DbCommand ConstructCountCommand(Database db)
        {
            return db.GetSqlStringCommand(SQL_COUNT);
        }

        protected override DbCommand ConstructCountConditionCommand(Database db, string condition)
        {
            return db.GetSqlStringCommand(SQL_COUNT + condition);
        }

		#endregion
		
		#region IsExist模块 Helper

        protected override DbCommand ConstructIsExistCommand(Database db, MoAssSubBranch entity)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_EXIST);
			db.AddInParameter(dbCommand,"AsisId",DbType.AnsiString,entity.AsisId);
			db.AddInParameter(dbCommand,"AssSubBranchId",DbType.AnsiString,entity.AssSubBranchId);
			return dbCommand;
        }

		#endregion

		
		
	}
}	
#endregion

